package com.youyi.yyscreencutlibrary.ColoPicker;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.internal.view.SupportMenu;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lkx.liandianqinew.R;
import com.youyi.yyscreencutlibrary.SDK.YYScreenCutSDK;
import com.youyi.yyscreencutlibrary.ShowMainActivity;
import org.greenrobot.eventbus.EventBus;

public class YYColorPickerActivity extends AppCompatActivity {
    private LinearLayout mMyMarkBottom;
    private String mNowColor;
    private int mNowX;
    private int mNowY;
    private TextView tvColor;

    /* access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.SupportActivity, android.support.v4.app.FragmentActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(1);
        getWindow().setFlags(1024, 1024);
        if (YYScreenCutSDK.mIsFinish) {
            EventBus.getDefault().post(new ShowMainActivity(true));
            finishMethod();
            return;
        }
        setContentView(R.layout.yy_activity_screen_color);
        TextView textView = (TextView) findViewById(R.id.mymark_cancel);
        this.tvColor = (TextView) findViewById(R.id.mymark_color);
        TextView textView2 = (TextView) findViewById(R.id.mymark_done);
        ZoomBitmapView zoomBitmapView = (ZoomBitmapView) findViewById(R.id.id_img);
        zoomBitmapView.setOnResultListener(new ZoomBitmapView.OnResultListener() {
            /* class com.youyi.yyscreencutlibrary.ColoPicker.YYColorPickerActivity.AnonymousClass1 */

            @Override // com.youyi.yyscreencutlibrary.ColoPicker.ZoomBitmapView.OnResultListener
            public void result(int i, int i2, String str) {
                YYColorPickerActivity.this.mNowX = i;
                YYColorPickerActivity.this.mNowY = i2;
                YYColorPickerActivity.this.mNowColor = str;
                if (str.equals("FF0000")) {
                    YYColorPickerActivity.this.tvColor.setTextColor(-1);
                } else {
                    YYColorPickerActivity.this.tvColor.setTextColor(-65536);
                }
                TextView textView = YYColorPickerActivity.this.tvColor;
                textView.setText("#" + str);
                TextView textView2 = YYColorPickerActivity.this.tvColor;
                textView2.setBackgroundColor(Color.parseColor("#" + str));
            }
        });
        zoomBitmapView.setBitmap(YYScreenCutSDK.mColorBitmap);
        this.mMyMarkBottom = (LinearLayout) findViewById(R.id.mymark_bottom);
        if (isScreenOriatationPortrait(this)) {
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) this.mMyMarkBottom.getLayoutParams();
            layoutParams.bottomMargin = getNavigationBarHeight(this);
            this.mMyMarkBottom.setLayoutParams(layoutParams);
        }
        textView.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yyscreencutlibrary.ColoPicker.YYColorPickerActivity.AnonymousClass2 */

            public void onClick(View view) {
                if (YYScreenCutSDK.mOnColorPickListener != null) {
                    YYScreenCutSDK.mOnColorPickListener.result(false, 0, 0, null);
                    YYScreenCutSDK.mOnColorPickListener = null;
                }
                YYColorPickerActivity.this.finishMethod();
            }
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yyscreencutlibrary.ColoPicker.YYColorPickerActivity.AnonymousClass3 */

            public void onClick(View view) {
                if (YYScreenCutSDK.mOnColorPickListener != null) {
                    YYScreenCutSDK.mOnColorPickListener.result(true, YYColorPickerActivity.this.mNowX, YYColorPickerActivity.this.mNowY, YYColorPickerActivity.this.mNowColor);
                    YYScreenCutSDK.mOnColorPickListener = null;
                }
                YYColorPickerActivity.this.finishMethod();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void finishMethod() {
        try {
            YYScreenCutSDK.mIsFinish = true;
            finish();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean isScreenOriatationPortrait(Context context) {
        return context.getResources().getConfiguration().orientation == 1;
    }

    private int getNavigationBarHeight(Context context) {
        Resources resources = context.getResources();
        return resources.getDimensionPixelSize(resources.getIdentifier("navigation_bar_height", "dimen", "android"));
    }

    @Override // android.support.v7.app.AppCompatActivity
    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (i != 4) {
            return super.onKeyDown(i, keyEvent);
        }
        if (YYScreenCutSDK.mOnColorPickListener != null) {
            YYScreenCutSDK.mOnColorPickListener.result(false, 0, 0, null);
            YYScreenCutSDK.mOnColorPickListener = null;
        }
        finishMethod();
        return true;
    }
}
